--later on when setting up the flag system. If player has certain flag his weapon handeling should be affected (weapon jamming?, weapon modding, accuracy)

local PLAYER = FindMetaTable("Player");

--Called on character Initialization or select.
function PLAYER:InitializeLoadout()
	
	local Loadout = self:CharacterGetData("Equipment");
	
	for key, equiped in pairs( Loadout ) do
		
		if equiped != "foo" then
			
			self:Give( equiped )
			
			if equiped != "envi_hands" then
			
				timer.Simple(.5, self.AddGear, self, GAME.WeaponToItem(equiped));
				
				
			end
			
		end

	end
	
	self:SelectWeapon("envi_hands");
	self:Give("gmod_tool");
	
end

--Slot refers to the equipment table keys. 
--(Misc, Secondary, Primary)

--Equip also refers to ply:Give(weapon)

--Note: Try and figure a way to alawys make sure if nothing is in misc then it is a hands swep
function PLAYER:EquipWeapon(weapon, slot)

	local Loadout = self:CharacterGetData("Equipment");
	
		Loadout[slot] = weapon;
		
	self:CharacterSetData(self:GetData("SelectedCharacter"), "Equipment", Loadout);
	self:Give(weapon);
	self:AddGear( GAME.WeaponToItem(weapon) );

end

function PLAYER:RemoveWeapon(slot)
	
	local Loadout = self:CharacterGetData("Equipment");
	local Weapon = Loadout[slot];

	if Loadout[slot] == "envi_hands" then return; end
	
		Loadout[slot] = "foo";
		
	self:StripWeapon(Weapon);
	self:RemoveGear(Weapon);
	self:InsertItem(GAME.WeaponToItem(Weapon).Name, nil);
	self:CharacterSetData(self:GetData("SelectedCharacter"), "Equipment", Loadout);

end

function GAME.SelectWeapon(ply, cmd, args)
	
	local Weapon = ply:CharacterGetData("Equipment")[args[1]];
	local weapon = ply:GetActiveWeapon().PrintName;
	
	if weapon != "envi_hands" then ply:AddGear( GAME.WeaponToItem(weapon) );end
	
	ply:SelectWeapon(Weapon);
	ply:RemoveGear(Weapon);
	
end
concommand.Add("gm_selectweapon", GAME.SelectWeapon);

function GAME.RemoveWeapon(ply, cmd, args)

	ply:RemoveWeapon(args[1]);
	
end
concommand.Add("gm_removeweapon", GAME.RemoveWeapon);

